
// 集成validator
import { ThrowStmt } from '@angular/compiler';
import { Component, forwardRef, Input, OnInit } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR} from "@angular/forms";
import { InputConfig } from "@src/app/model/jack.model";

@Component({
  selector: 'jack-input',
  templateUrl: './input.component.html',
  styleUrls: ['./input.component.css'],
  providers:[{
    provide:NG_VALUE_ACCESSOR,
    useExisting:forwardRef(() => InputComponent),
    multi:true
  }]

})
export class InputComponent implements OnInit , ControlValueAccessor{
  @Input() conf: InputConfig;
  @Input() ngModel;
  model = '';
  writeValue(value: any){
    this.model = value
  }
  registerOnChange(fn:Function):void {
    console.log('register on change')
    this.onmodelchange= fn;
  }
  registerOnTouched(fn:Function):void {
    console.log('register touch')
    this.onmodeltouch = fn;
  }


  constructor() { }


  ui = {
    placeholder:''
  }
  ngOnInit(): void {
  }

  onchange() {
    if(!this.conf) {
      return;
    }
    this.conf.onchange && this.conf.onchange()
  }
  onmodelchange:Function = (value) => {
    this.model = value

  }

  onmodeltouch:Function  = () => {

  }

}
